package lab_1;

import java.util.Date;
import java.rmi.*;
import java.rmi.server.*;

/**
 * 
 * @author grp02 - Pascal Charreix and Meike Paetz
 *
 * This is the implementation of the HPackage remote interface.
 */
public class HPackageImpl extends UnicastRemoteObject implements HPackage {

    static private int nbrPackages;
    private boolean pLock;
    private boolean pReserved;
    private String pCountry;
    private Date pJourneyStart;
    private Date pJourneyEnd;
    private String pHotelName;
    private int pHotelStars;
    private String pFlightOperator;
    private float pPrice;
    private int pId;

    /**
     * creates a new Holiday Package
     */
    public HPackageImpl(String Country, Date Start, Date End, String HotelName, int HotelStars, String FlightOperator, float Price) throws RemoteException {
        pLock = false;
        pReserved = false;
        pId = nbrPackages++;
        pCountry = Country;
        pJourneyStart = Start;
        pJourneyEnd = End;
        pHotelName = HotelName;
        pHotelStars = HotelStars;
        pFlightOperator = FlightOperator;
        System.out.println("Package " + String.valueOf(pId) + " created.");
    }

    
    /**  
     * Constructor of the Package Implementation
     */
    public HPackageImpl(int id) throws RemoteException {
        pId = id;
    }

    /**
     * returns all information of a Holiday Package
     */
    @Override
    public String getFullInformation() throws RemoteException {
        String result = new String();
        result = "Package " + String.valueOf(pId) + ":\n" + pCountry + " - from "
                + pJourneyStart + " to " + pJourneyEnd + " in " + pHotelName
                + "(" + String.valueOf(pHotelStars) + " stars) flying with " + pFlightOperator + "\n";
        return result;
    }

    /**
     * returns the country of a Holiday Package
     */
    public String getCountry() throws RemoteException {
        return pCountry;
    }

    /**
     * returns journey dates of a Holiday Package
     */
    public Date[] getJourneyDates() throws RemoteException {
        Date[] result = new Date[2];
        result[0] = pJourneyStart;
        result[1] = pJourneyEnd;
        return result;
    }

    /**
     * returns hotel name of a Holiday Package
     */
    public String getHotelName() throws RemoteException {
        return pHotelName;
    }

    /**
     * returns hotel stars of a Holiday Package
     */
    public int getHotelStars() throws RemoteException {
        return pHotelStars;
    }

    /**
     * returns flight operator of a Holiday Package
     */
    public String getFlightOperator() throws RemoteException {
        return pFlightOperator;
    }

    /**
     * returns price of a Holiday Package
     */
    public float getPrice() throws RemoteException {
        return pPrice;
    }

    /**
     * creatretuns the reservation number of a Holiday Package
     */
    @Override
    public int getReservationNbr() throws RemoteException {
        return pId;
    }

    /**
     * reserves a Holiday Package
     */
    @Override
    public int reserve() throws RemoteException {
        pReserved = true;
        System.out.println("Package " + String.valueOf(pId) + " reserved.");
        return pId;
    }

    /**
     * cancels a reserved Holiday Package
     */
    @Override
    public void cancel() throws RemoteException {
        pReserved = false;
        System.out.println("Package " + String.valueOf(pId) + " canceled.");
    }

    /**
     * unlocks a Holiday Package
     */
    @Override
    public void unlock() throws RemoteException {
        pLock = false;
        System.out.println("Package " + String.valueOf(pId) + " unlocked.");
    }

    /**
     * locks a Holiday Package
     */
    @Override
    public void lock() throws RemoteException {
        pLock = true;
        System.out.println("Package " + String.valueOf(pId) + " locked.");
    }

    /**
     * gives back lock state of the Holiday Package
     */
    public boolean isLocked() throws RemoteException {
        return pLock;
    }

    /**
     * gives back reservation state of the Holiday Package
     */
    public boolean isReserved() throws RemoteException {
        return pReserved;
    }
}
